package org.infinitest.intellij;

import static org.easymock.EasyMock.*;
import org.junit.Before;
import org.junit.Test;

import javax.swing.*;

public class WhenLaunchingInfinitest {
  private ModuleSettings moduleSettings;
  private InfinitestAnnotatorLocator annotatorLoator;

  @Before
  public void setUp() throws Exception {
    moduleSettings = new FakeModuleSettings("foo");
    annotatorLoator = new InfinitestAnnotatorLocator() {
      public InfinitestAnnotator findInfinitestAnnotator() {
        return new FakeInfinitestAnnotator();
      }
    };
  }

  @Test
  public void shouldTriggerProjectRebuild() {
    ProjectCompiler compiler = createMock(ProjectCompiler.class);

    compiler.forceRebuild();
    expectLastCall().once();

    replay(compiler);

    InfinitestRunner runner = new InfinitestRunner(moduleSettings, new FakeToolWindowRegistry(),
            new FakeCompilationNotifier(), compiler, annotatorLoator);
    runner.run();

    verify(compiler);
  }

  @Test
  public void shouldNameToolWindowAfterModule() {
    ToolWindowRegistry registry = createMock(ToolWindowRegistry.class);

    registry.registerToolWindow((JPanel) anyObject(), matches("Infinitest_foo"));
    expectLastCall().once();

    replay(registry);

    InfinitestRunner runner = new InfinitestRunner(moduleSettings, registry,
            new FakeCompilationNotifier(), new FakeProjectCompiler(), annotatorLoator);
    runner.run();

    verify(registry);
  }
}